package plateforme.controlleur;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;

/**
 * Servlet implementation class ControlleurSuppPerson
 */
public class ControlleurSuppPerson extends HttpServlet {
	private static final long serialVersionUID1 = 1L;
       
  
    	private ServletConfig config;
//Setting JSP page

  String page="supprimer_utilisateur.jsp";
 
 
  
  
  public void init(ServletConfig config) throws ServletException{

 this.config=config;

 }

/**
 * 
 */
private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {


    
	//Establish connection to MySQL database
	String connectionURL = "jdbc:mysql://localhost:3306/laas";
	Connection connection= null;
	 ResultSet rs;
	 response.setContentType("text/html");
	 List<String> dataList = new ArrayList<String>();
	
	   try {

		 // Load the database driver

		  Class.forName("com.mysql.jdbc.Driver");

		  // Get a Connection to the database

		  connection = (Connection) DriverManager.getConnection(connectionURL, "root", ""); 
		//Select the data from the database
		 // String sql = "select * from fournisseur" ;
		  
		 String admin="admin";
		String sql1 = "select * from personne where role!='"+admin+"'" ;
		  Statement s = (Statement) connection.createStatement();

		  s.executeQuery (sql1);

		  rs = (ResultSet) s.getResultSet();

		  while (rs.next ()){
			  
		  
		   
		  //Add records into data list

		  dataList.add(rs.getString(1));

		  dataList.add(rs.getString(2));

		  dataList.add(rs.getString(3));
		  
		  dataList.add(rs.getString(4));
		  dataList.add(rs.getString(5));
		  dataList.add(rs.getString(6));
		  dataList.add(rs.getString(7));
		  dataList.add(rs.getString(8));
		  }

		  rs.close ();

		  s.close ();

		  }catch(Exception e){

		  System.out.println("Exception is ;"+e);

		  }
	 
		  

		  //Disptching request
          
        	  
	 request.setAttribute("data",dataList);

	  //Disptching request
	  RequestDispatcher dispatcher = request.getRequestDispatcher(page);

	  if (dispatcher != null){

	  dispatcher.forward(request, response);

	  } 

	  }
	
		 
		
}

		  
   
	   
	 











